//
//  HotImageTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotImageTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation HotImageTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createHotImage];
    }
    
    return self;
}

-(void)createHotImage{
    self.avatarImage = [[UIImageView alloc] init];
   // self.avatarImage.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.avatarImage];
    [self.avatarImage sizeToFit];
    self.authorLabel = [[UILabel alloc] init];
  //  self.authorLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.authorLabel];
    
    self.titleLabel = [[UILabel alloc] init];
 //   self.titleLabel.backgroundColor = [UIColor lightGrayColor];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    
    self.imageOne = [[UIImageView alloc] init];
 //   self.imageOne.backgroundColor = [UIColor magentaColor];
    [self.contentView addSubview:self.imageOne];
    self.imageTwo = [[UIImageView alloc] init];
 //   self.imageTwo.backgroundColor = [UIColor magentaColor];
    [self.contentView addSubview:self.imageTwo];
    self.imageThree = [[UIImageView alloc] init];
 //   self.imageThree.backgroundColor = [UIColor magentaColor];
    [self.contentView addSubview:self.imageThree];
    
    self.forumLabel = [[UILabel alloc] init];
 //   self.forumLabel.backgroundColor = [UIColor grayColor];
    self.forumLabel.textColor = [UIColor greenColor];
    [self.contentView addSubview:self.forumLabel];
    
    self.reply_timeLabel = [[UILabel alloc] init];
  //  self.reply_timeLabel.backgroundColor = [UIColor grayColor];
    self.reply_timeLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.reply_timeLabel];
    
    self.reply_numLabel = [[UILabel alloc] init];
//    self.reply_numLabel.backgroundColor = [UIColor grayColor];
    self.reply_numLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.reply_numLabel];
    

    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.avatarImage.frame = CGRectMake(10 * WIDTHC, 10 * WIDTHC, 50 * WIDTHC, 50 * WIDTHC);
    
    self.avatarImage.layer.masksToBounds = YES;
    self.avatarImage.layer.cornerRadius = 25 * WIDTHC;
    
    self.authorLabel.frame = CGRectMake(self.avatarImage.frame.size.width + 10 , self.avatarImage.frame.origin.y -10, 100 * WIDTHC, 30 * WIDTHC);
    
    self.authorLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.frame = CGRectMake(self.authorLabel.frame.origin.x, self.authorLabel.frame.origin.y + 15 , self.contentView.frame.size.width - self.avatarImage.frame.size.width - 20, self.contentView.frame.size.height / 4);
    self.imageOne.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height ,80 *WIDTHC ,80 * WIDTHC );
    self.imageTwo.frame = CGRectMake(self.imageOne.frame.size.width + self.imageOne.frame.origin.x + 20, self.imageOne.frame.origin.y, self.imageOne.frame.size.width, self.imageOne.frame.size.height);
      self.imageThree.frame = CGRectMake(self.imageTwo.frame.size.width + self.imageTwo.frame.origin.x + 20 , self.imageTwo.frame.origin.y, self.imageOne.frame.size.width, self.imageOne.frame.size.height);
    self.forumLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.imageOne.frame.size.height + self.imageOne.frame.origin.y , self.imageOne.frame.size.width * 2, self.authorLabel.frame.size.height * 0.8);
    
    self.reply_timeLabel.frame = CGRectMake(self.forumLabel.frame.size.width / 2 * 3, self.forumLabel.frame.origin.y, self.forumLabel.frame.size.width / 2, self.forumLabel.frame.size.height);
    self.reply_numLabel.frame = CGRectMake(self.forumLabel.frame.size.width / 2 * 4 + 10, self.forumLabel.frame.origin.y, self.forumLabel.frame.size.width / 2, self.forumLabel.frame.size.height);

}

-(void)setHotModel:(HotModel *)hotModel{
    _hotModel = hotModel;
    NSMutableArray *modelArray = hotModel.bigpic_arr;
    switch (modelArray.count) {
        case 1:
            [self.imageOne sd_setImageWithURL:hotModel.bigpic_arr[0]];
            [self.imageTwo sd_setImageWithURL:nil];
            [self.imageThree sd_setImageWithURL:nil];
            break;
        case 2:
            [self.imageOne sd_setImageWithURL:hotModel.bigpic_arr[0]];
            [self.imageTwo sd_setImageWithURL:hotModel.bigpic_arr[1]];
            [self.imageThree sd_setImageWithURL:nil];
            break;
       
        default:
            [self.imageOne sd_setImageWithURL:hotModel.bigpic_arr[0]];
            [self.imageTwo sd_setImageWithURL:hotModel.bigpic_arr[1]];
            [self.imageThree sd_setImageWithURL:hotModel.bigpic_arr[2]];
            break;
    }
    
    [self.avatarImage sd_setImageWithURL:[NSURL URLWithString:hotModel.avatar]];
    self.authorLabel.text = hotModel.author;
    self.titleLabel.text = hotModel.title;
    self.forumLabel.text = hotModel.forum;
    self.reply_timeLabel.text = hotModel.reply_time;
    self.reply_numLabel.text = [hotModel.reply_num stringValue];

    
    
}

@end
